package com.jixi.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.jixi.common.result.PageResult;
import com.jixi.common.result.Result;
import com.jixi.pojo.dto.EducationLoginDto;
import com.jixi.pojo.dto.EducationRegisterDto;
import com.jixi.pojo.entity.Education;
import com.jixi.service.EducationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/education")
public class EducationController {

	@Autowired
	private EducationService educationService;

	/**
	 * 教育局注册
	 *
	 * @param educationRegisterDto 教育局注册Dto
	 * @return 注册结果
	 */
	@PostMapping("/education/register")
	public Result educationRegister(@RequestBody EducationRegisterDto educationRegisterDto) {
		return educationService.educationRegister(educationRegisterDto);
	}
	
	/**
	 * 教育局登录
	 *
	 * @param educationLoginDto 教育局登录Dto
	 * @return 登录结果
	 */
	@PostMapping("/login")
	public Result educationLogin(@RequestBody EducationLoginDto educationLoginDto) {
		return educationService.educationLogin(educationLoginDto);
	}
	
	/**
	 * 重置密码
	 *
	 * @param educationId   教育局id
	 * @param resetPassword 重置密码
	 * @return 重置结果
	 */
	@PutMapping("/education/resetPassword")
	public Result resetPassword(Long educationId, String resetPassword) {
		return educationService.educationResetPassword(educationId,resetPassword);
	}
	
	/**
	 * 修改密码
	 *
	 * @param oldPassword 旧密码
	 * @param newPassword 新密码
	 * @param rePassword  重复新密码
	 * @return 修改结果
	 */
	@PutMapping("/education/updatePassword")
	public Result updatePassword(String oldPassword, String newPassword, String rePassword) {
		log.info("修改密码请求:{},{},{}", oldPassword, newPassword, rePassword);
		return educationService.educationUpdatePassword(oldPassword,newPassword,rePassword);
	}
	
	/**
	 * 获取教育局信息
	 *
	 * @return 教育局信息
	 */
	@GetMapping("/education/info")
	public Result<Education> getInfo() {
		Education education = educationService.getEducationinfo();
		return Result.success(education);
	}
	
	/**
	 * 教育局修改信息
	 *
	 * @param educationNickname 教育局昵称
	 * @param educationTel      联系电话
	 * @return 修改结果
	 */
	@PutMapping("/education/updateInfo")
	public Result updateInfo(String educationNickname, String educationTel) {
		return educationService.educationUpdateInfo(educationNickname, educationTel);
	}
	
	/**
	 * 教育局列表条件分页查询
	 *
	 * @param pageNum           页码
	 * @param pageSize          页大小
	 * @param educationNickname 教育局昵称
	 * @param educationPower    权限
	 * @param status            状态
	 * @return 教育局列表
	 */
	@GetMapping("/education/list")
	public Result<PageResult> educationList(
			Integer pageNum,
			Integer pageSize,
			String educationNickname,
			Integer educationPower,
			Integer status
	) {
		return educationService.educationPage(pageNum,pageSize,educationNickname,educationPower,status);
	}
	
	/**
	 * 修改权限
	 *
	 * @param educationId    教育局Id
	 * @param educationPower 权限
	 * @return 修改结果
	 */
	@PutMapping("/education/permission")
	public Result updatePermission(Long educationId, Integer educationPower) {
		return educationService.educationPermission(educationId,educationPower);
	}
	
	/**
	 * 修改状态
	 *
	 * @param educationId 教育局Id
	 * @param status      教育局状态
	 * @return 修改结果
	 */
	@PutMapping("/education/status")
	public Result updateStatus(Long educationId, Integer status) {
		return educationService.updateEducationStatus(educationId,status);
	}
	
	/**
	 * 删除账号
	 *
	 * @param educationId 教育局id
	 * @return 删除结果
	 */
	@DeleteMapping("/education/delete")
	public Result delete(Long educationId) {
		return educationService.deleteEducationById(educationId);
	}
	
	/**
	 * 登出
	 *
	 * @return 登出结果
	 */
	@PostMapping("/logout")
	public Result logout() {
		StpUtil.logout();
		return Result.success("登出成功");
	}
	
}
